package lp.xian.equipment.controller;


import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import lp.xian.equipment.domain.Classify;
import lp.xian.equipment.service.IClassifyservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 供应商分类
 */
@RestController
@RequestMapping("/classify/classify")
public class ClassifyController extends BaseController {
    @Autowired
    private IClassifyservice classifyservice;
    @PreAuthorize("@ss.hasPermi('classify:classify:list')")
    @GetMapping("/list")
    public TableDataInfo list(Classify classify){
        startPage();
        List<Classify> list=classifyservice.listClassify(classify);
        return getDataTable(list);
    }
    /**
     * 导出供应商分类列表
     */
    @PreAuthorize("@ss.hasPermi('classify:classify:query')")
    @Log(title = "供应商分类",businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response,Classify classify){
        List<Classify> list=classifyservice.listClassify(classify);
        ExcelUtil<Classify> util=new ExcelUtil<Classify>(Classify.class);
        util.exportExcel(response,list,"供应商分类数据");
    }

    /**
     * 获取供应商分类详细
     */
    @PreAuthorize("@ss.hasPermi('classify:classify:query')")
    @GetMapping("/{classifyId}")
    public AjaxResult getInfo(@PathVariable("classifyId")Integer classifyId){
        return AjaxResult.success(classifyservice.getByIdClassify(classifyId));
    }

    /**
     * 新增供应商分类列表
     */
    @PreAuthorize("@ss.hasPermi('classify:classify:add')")
    @Log(title = "供应商分类",businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult add(@RequestBody Classify classify){
        return toAjax(classifyservice.save(classify));
    }

    /**
     * 修改供应商分类列表
     */
    @PreAuthorize("@ss.hasPermi('classify:classify:edit')")
    @Log(title = "供应商分类",businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Classify classify){
        return toAjax(classifyservice.update(classify));
    }

    /**
     * 删除供应商分类列表
     */
    @PreAuthorize("@ss.hasPermi('classify:classify:remove')")
    @Log(title = "供应商分类",businessType = BusinessType.DELETE)
    @DeleteMapping("/{classifyIds}")
    public AjaxResult remove(@PathVariable Integer[] classifyIds){
        return toAjax(classifyservice.deletees(classifyIds));
    }

}
